export function getPuduct (data, val) {
  let newArray = []
  // postParam:["productId","skuId","promotionPrice","isMustBuy"]
  // getParam:['productId','id','salePrice','isShelf']
  for (let item of data) {
    for (let todo of item[val.child]) {
      newArray.push({
        'productId': todo[val.getParam[0]],
        'skuId': todo[val.getParam[1]],
        'promotionPrice': todo[val.getParam[2]],
        'isMustBuy': item[val.getParam[3]] })
    }
  }
  return newArray
}
const plusZero = (value) => {
  return value < 10 ? '0' + value : value
}
export function formatDate (value, hasTime) {
  if (!value) return ''
  if (typeof value === 'string') {
    value = value.replace(/\-/g, '/')
  }
  value = new Date(value)
  let result = ''
  let year = value.getFullYear()
  let month = value.getMonth() + 1
  let day = value.getDate()

  month = plusZero(month)
  day = plusZero(day)

  result = year + '-' + month + '-' + day

  if (hasTime) {
    let hour = value.getHours()
    let minute = value.getMinutes()
    let seconds = value.getSeconds()
    hour = plusZero(hour)
    minute = plusZero(minute)
    seconds = plusZero(seconds)
    result += ' ' + hour + ':' + minute + ':' + seconds
  }

  return result
}
export function setSelectList (data, val) {
  for (let item of data) {
    item.label = item[val.label]
    item.value = item[val.value]
  }
  return data
}
export function setCascaderList (data, val) {
  for (let item of data) {
    item.label = item[val.mt][val.label]
    item.value = item[val.mt][val.value]
    item.children = item[val.child]
    if (item[val.child] && item[val.child].length) {
      setCascaderList(item[val.child], val)
    }
  }
}
export function getValue (data, val) {
  let newArray = []
  data.map(function (item, index, array) {
    newArray.push({ m: item[val.index], n: '0', isParcel: item[val.index1] })
  })
  return newArray
}
export function getValue1 (data, val) {
  let newArray = []
  data.map(function (item, index, array) {
    newArray.push({ 'denomination': item[val.index1] == 'custom' ? item[val.index4] : item[val.index1], 'useCondition': item[val.index2], 'validityDays': item[val.index3] })
  })
  return newArray
}
